package interpreter.main.express;

import interpreter.main.context.Context;

/**
 * Program表达式
 */
public class ProgramExpression implements IExpressions {
    //上下文环境
    private final Context context;
    //当前命令
    private final static String COMMAND = "PROGRAM";

    //存储下一个表达式引用
    private IExpressions expressions;

    public ProgramExpression(String text) {
        this.context = new Context(text);
        this.pares(this.context);
    }

    /**
     * 解析
     */
    @Override
    public void pares(Context context) {
        this.context.next();
    }

    /**
     * 执行方法
     */
    @Override
    public void interpret() {
        //判断是否以PROGRAM开始
        if (!this.context.equalsWithCommand(COMMAND)) {
            System.out.println("不是PROGRAM开头");
        } else {
            this.context.next();
            this.expressions = new ListExpression();
            this.expressions.pares(this.context);
            //listExpression表达式开始解析
            this.expressions.interpret();
        }
    }
}
